package com.xneure.database.extend;

import org.apache.ibatis.binding.MapperProxy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import com.xneure.database.dao.DataBaseDao;
import com.xneure.utils.ObjectUtil;

//@Component
public class LoadSafeBean implements BeanPostProcessor{
	@Override
	public Object postProcessBeforeInitialization(Object bean,String beanName) throws BeansException{
		return bean;
	}

	@SuppressWarnings({"rawtypes", "unchecked"})
	@Override
	public Object postProcessAfterInitialization(Object bean,String beanName) throws BeansException{
		if(DataBaseDao.class.isAssignableFrom(bean.getClass())){
			Object target = ObjectUtil.getFieldValue(bean,"h","advised","targetSource","target");
			MapperProxy mapperProxy = (MapperProxy)ObjectUtil.getFieldValue(target,"h");
			ObjectUtil.modifyFieldValue(target,"h",new MapperParamProxy(mapperProxy));
			System.out.println(mapperProxy);
		}
		return bean;
	}
}
